﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using RuoVea.ExDto;
using RuoVea.ExEnum;
using RuoVea.ExLog;
using RuoVea.ExUtil;
using RuoVea.ExWeb.Jwt;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RuoVea.WebTest.Controllers
{
    public class ssss
    {
        [JsonConverter(typeof(LongToStringConverter))]
        public long sss { get; set; }
    }

    /// <summary>
    /// 健康检查
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class HealthCheckController : ControllerBase
    {
        /// <summary>
        /// 健康检查接口
        /// </summary>
        /// <returns></returns>
        [HttpGet("geet")]
        public IActionResult Get()
        {
            try
            {
                int yy = 0;
                var tt = 1 / yy;
            }
            catch (Exception ex) {
                LogFactory.Error(ex);
            }
            LogFactory.Error("eretertertere");
            //string d=   JWTEncryption.Exchange("", "",
            //       (x) =>
            //       {
            //           return "asdasd";
            //       },
            //   (a, b, c) => { 

            //   });


            return Ok();
        }

        [HttpGet("long")]
        public IActionResult MyTables()
        {
            //TokenModel tokenModel = new TokenModel
            //{
            //    Id = "1222",
            //    Name = "nmeaaa",
            //    Roles =string.Join(",",new List<string> {"asd","asdasdsa" }),
            //    Claims = new Claim(ClaimsIdentity.DefaultNameClaimType, "1")
            //};

            TokenEntity tokenModel = new TokenEntity
            {
                UserId = "1",
                RoleIds = string.Join(",", (new List<string> { "api_access" })),
                Account = "Paul",
                IsAdmin = "0",
                Name = "asdsa",
                TenantId = "10001"
            };
            var jwtStr = ExWeb.Jwt.JWTEncryption.Encrypt(tokenModel);//登录，获取到一定规则的 Token 令牌
            ssss sss = new ssss() { sss = 1462699114633629696 };
            var tty = new RestfulResult { Code = HttpStatusCode.OK, Data = sss }.Json2Str();
            return Content(tty);
            //return Content(jwtStr);
        }

        [HttpGet("user")]
        public IActionResult MyTables2()
        {
            //EntityBuild();
            //ServerBuild();
            //DtoBuild();
            //return Content("Build Success");

            var t = this.User;
            //var User = App.User;

            return Content("asdfasdasd"/*App.HttpContext.Request.Path*/);
        }

    }
}
